-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(file-log) add timeout to reopen files automatically #2348
Conversation
|
yes. if there is 60 seconds without any request, then in second 61, a request comes in, it will be closed and opened again.
Same as what happens now, gets written to the old file-descriptor, so yes, gets lost. Can be mitigated by setting it to 1 second for example. Less gets lost, but will be (slightly) slower There is no simple way around this, other than rebuild syslog inside openresty. This is the pretty much the best we can do, if that's not enough, stop using it and use the syslog plugin instead. |
Rather than worrying about a single FD, why don't we have the plugin buffer the contents and asynchronously flush the buffer to disk. This is the same model as used by the buffer directive of the nginx access_log directive, doesn't result lost data points, and resolves the rotated fd bug. The overhead of opening and closing the fd on a recurring basis at this scale (given a flush time on the order of seconds) is negligible. |
A few possibilities:
I feel reopening files is not the biggest issue anyway, compared to blocking io in general. I'm actually not sure if there is issue also with multiple workers writing the same file, and get output mixed (do writers hold exclusive locks?) |
Not 100% sure but that |
assert.is_nil(err) | ||
assert(not file_log:find(uuid1, nil, true), "did not expected 1st request in logfile") | ||
assert(file_log:find(uuid2, nil, true), "expected 2nd request in logfile") | ||
assert(file_log:find(uuid2, nil, true), "expected 3rd request in logfile") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Buggy test, this should be uuid3?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed!
If files got rotated, the plugin would keep writing to the existing filedescriptor, instead of recreating a new file. The new `valid` property (in seconds) will automatically reopen the file after the specified number of seconds.
@thefosk If you don't want any lost data, setting the timeout to 0 will close and reopen on every request. Hence when rotating, set it temporarily to 0, rotate the log, and set it back to a higher value. That ought to work without loosing any data. @p0pr0ck5 @bungle Though the ideas mentioned do make sense, in the end they don't resolve the underlying usage of blocking i/o. Hence this is the minimum viable fix for the file-log plugin. I don't feel any more effort spend on this is worthwhile as they don't fix the blocking i/o. So imo if this is not good enough, use syslog. |
This seems like an unnecessarily complex and arbitrary step needed to simply rotate a file. Do really want to tell everyone that wants to rotate logs like this to jump through these hoops?
Neither does this PR :) Blocking I/O isn't the question here. Stale FDs is.
I disagree. The simplest fix to the issue of stale FDs would be to simply not cache the FD at all. A recurring close/open adds additional complexity and overhead. |
Another approach that comes to mind would be to provide an API hook to cycle the FDs, similar to what |
I agree with @p0pr0ck5 that this does not seem necessary and would be asking our customers to do a lot of manual work. This is becoming a serious issue (potential showstopper) for some users. |
Do we still have a concern about |
Closing this in favor of a strategy to optionally close the fd on each invocation, per conversations with @Tieske and @thefosk. @john-paul-keenan a gentle reminder that this plugin is highly unsuitable for high-performance productions environments, not as a result of the design of the plugin per se, but the nature of disk access and OpenResty's architecture and idiomatic paradigms :) |
If files got rotated, the plugin would keep writing to the existing file-descriptor, instead of recreating a new file. The new
valid
property (in seconds, default 60) will automatically reopen the file after the specified number of seconds.This is modeled after the nginx directive open_log_file_cache, which has a similar
valid
property, with the same default.Remains: this plugin is not really suitable for production use. There are too many issues related to blocking io, file errors, etc. Those have been properly solved by tools like
syslog
etc. so those remain the preferred solution.Issues resolved
Fix #2325